<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="single"
          @click="handleAllPut"
          v-hasPermi="['putStorage:halfFinish:allPut']"
        >
          一键入库
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="single"
          @click="handlePast"
          v-hasPermi="['putStorage:halfFinish:post']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          @click="check_collect = true"
          size="mini"
          v-hasPermi="['putStorage:halfFinish:collect']"
          >汇总</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="single"
          @click="check_back = true"
          v-hasPermi="['putStorage:halfFinish:back']"
        >
          撤回开单
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:halfStart:export']"
        >
          导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:RpmMstr:export']"
        >
          入库明细
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:RpmMstr:export']"
        >
          入库统计
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      :height="tableH"
      v-loading="loading"
      :cell-style="iCellStyle"
      :data="RpmMstrList"
      @row-click="clickRows"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <el-table-column
        label="入库单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="rpmDjbh"
      />
      <el-table-column
        label="入库日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmRkrq"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rpmRkrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="入库类型"
        :show-overflow-tooltip="true"
        width="110"
        align="center"
        prop="rpmType"
      >
        <template #default="scope">
          <dict-tag :options="rpmTypeOptions" :value="scope.row.rpmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="入库仓库"
        :show-overflow-tooltip="true"
        width="120"
        align="center"
        prop="rpmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allCkStorageOptions" :value="scope.row.rpmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="班次"
        :show-overflow-tooltip="true"
        width="90"
        align="center"
        prop="rpmBcdm"
      />
      <el-table-column
        label="客户代码"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="rpmKhdm"
      >
        <template #default="scope">
          <dict-tag :options="allCustomerOptions" :value="scope.row.rpmKhdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="开单人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJlry"
      />
      <el-table-column
        label="检验结果"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJyjg"
      />
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="120"
        align="center"
        prop="rpmDesc"
      />
      <el-table-column
        label="开单日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmJlrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="检验人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJyry"
      />
      <el-table-column
        label="检验日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmJyrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmJyrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmGzrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmGzrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="100"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="printHandle(scope.row)"
            :disabled="
              !['6', '2'].includes(scope.row.rpmZtbz) ||
              scope.row.rpmTjflag != '1'
            "
            v-hasPermi="['putStorage:halfFinish:print']"
          >
            单据打印
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--子表Tab-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="入库明细" name="first">
        <el-table
          border
          stripe
          :cell-style="iCellStyle2"
          :height="tableHChild"
          :data="RpdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
          :fit="true"
        >
          <el-table-column
            label="#"
            type="index"
            width="40"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="客户编号"
            width="150"
            align="center"
            prop="rpdCusWldm"
            fixed="left"
          />
          <el-table-column
            label="制造单号"
            width="135"
            align="center"
            prop="rpdZzdh"
          />
          <el-table-column
            label="机台"
            width="80"
            align="center"
            prop="rpdJtbh"
          />
          <el-table-column
            label="物料代码"
            width="135"
            align="center"
            prop="rpdWldm"
          />
          <el-table-column
            label="产品名称"
            width="135"
            align="center"
            prop="rpdWlpm"
          />
          <el-table-column
            label="产品规格"
            width="135"
            align="center"
            prop="rpdWlgg"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="rpdDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.rpdDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            width="80"
            align="center"
            prop="rpdSqsl"
          />
          <el-table-column
            label="允收数量"
            width="80"
            align="center"
            prop="rpdOksl"
          />
          <el-table-column
            label="拒收数量"
            width="80"
            align="center"
            prop="rpdNgsl"
          />
          <el-table-column
            label="入库数量"
            width="80"
            align="center"
            prop="rpdRksl"
          />
          <el-table-column
            label="箱包装数"
            width="80"
            align="center"
            prop="rpdMxsl"
          />
          <el-table-column
            label="检验人员"
            width="80"
            align="center"
            prop="rpdJyry"
          />
          <el-table-column
            label="检验日期"
            width="80"
            align="center"
            prop="rpdJyrq"
          />
          <el-table-column
            label="备注"
            width="120"
            align="center"
            prop="rpdDesc"
          />
          <el-table-column
            label="检验结果"
            width="120"
            align="center"
            prop="rpdJyjg"
          />
          <el-table-column
            label="结果描述"
            width="120"
            align="center"
            prop="rpdJyms"
          />
          <el-table-column
            label="入库人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rpdRkry"
          />
          <el-table-column
            label="入库日期"
            :show-overflow-tooltip="true"
            align="center"
            prop="rpdRkrq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.rpdRkrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="箱号"
            width="120"
            align="center"
            prop="rrqXs"
          />
          <el-table-column
            label="生产日期"
            :show-overflow-tooltip="true"
            align="center"
            prop="rrqRq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.rrqRq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="入库统计" name="second">
        <el-row type="flex">
          <el-table
            border
            stripe
            :cell-style="iCellStyle2"
            @row-click="clickRowChilds"
            :data="RpdDetTotal"
            :height="tableHChild"
          >
            <el-table-column
              label="#"
              width="40"
              fixed="left"
              type="index"
              align="center"
            />
            <el-table-column
              label="客户编号"
              width="150"
              fixed="left"
              show-overflow-tooltip
              align="center"
              prop="rpdCusWldm"
            />
            <el-table-column
              label="物料代码"
              width="100"
              show-overflow-tooltip
              align="center"
              prop="rpdWldm"
            />
            <el-table-column
              label="产品名称"
              min-width="150"
              show-overflow-tooltip
              align="center"
              prop="rpdWlpm"
            />
            <el-table-column
              label="产品规格"
              min-width="150"
              show-overflow-tooltip
              align="center"
              prop="rpdWlgg"
            />
            <el-table-column
              label="单位"
              :show-overflow-tooltip="true"
              width="55"
              align="center"
              prop="rpdDw"
            >
              <template #default="scope">
                <dict-tag :options="unitFlagOptions" :value="scope.row.rpdDw" />
              </template>
            </el-table-column>
            <el-table-column
              label="申请数量"
              width="75"
              align="center"
              prop="rpdSqsl"
            />
            <el-table-column
              label="允收数量"
              width="75"
              align="center"
              prop="rpdOksl"
            />
            <el-table-column
              label="拒收数量"
              width="75"
              align="center"
              prop="rpdNgsl"
            />
            <el-table-column
              label="入库数量"
              width="75"
              align="center"
              prop="rpdRksl"
              fixed="right"
            />
            <el-table-column
              fixed="right"
              label="操作"
              align="center"
              width="80"
              class-name="small-padding fixed-width"
            >
              <template #default="scope">
                <el-button
                  size="mini"
                  type="text"
                  :disabled="scope.row.rpdRksl >= scope.row.rpdOksl || single"
                  @click="handRpdPut(scope.row)"
                >
                  确认入库
                </el-button>
              </template>
            </el-table-column>
          </el-table>

          <el-table
            border
            stripe
            :data="RplList"
            :height="tableHChild"
            style="flex: 0 0 160px"
          >
            <!-- <el-table-column label="#" width="40" type="index" align="center" />
              <el-table-column label="存放位置" :show-overflow-tooltip="true" align="center" prop="rplCwdm">
                <template #default="scope">
                  <dict-tag :options="cwStorageOptions" :value="scope.row.rplCwdm" />
                </template>
              </el-table-column> -->
            <el-table-column
              label="入库数量"
              width="80"
              show-overflow-tooltip
              align="center"
              prop="rplRksl"
            />
            <el-table-column
              label="操作"
              align="center"
              width="80"
              class-name="small-padding fixed-width"
            >
              <template #default="scope">
                <el-button
                  size="mini"
                  type="text"
                  :disabled="single"
                  @click="handRplDel(scope.row.rplId)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </el-tab-pane>
    </el-tabs>
    <!-- 检验结果对话框   -->
    <el-dialog
      :title="title"
      v-model="gzOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="88px" :rules="rules">
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rplDjbh">
            <el-input v-model="form.rplDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="rplWldm">
            <el-input v-model="form.rplWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="品名规格" prop="rplPmgg">
            <el-input v-model="form.rplPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="允收数量" prop="rplOksl">
            <el-input v-model="form.rplOksl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="已入库数" prop="rplYrsl">
            <el-input v-model="form.rplYrsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="待入库数" prop="rplDrsl">
            <el-input v-model="form.rplDrsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请入库" prop="rplRksl">
            <el-input type="number" v-model="form.rplRksl" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="存放位置" prop="rplCwdm">
            <el-select
              v-model="form.rplCwdm"
              class="input240"
              placeholder="请选择入库类型"
              clearable
              size="small"
              disabled
            >
              <el-option
                v-for="dict in cwStorageOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleRpdPost">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <Modal v-model="check_collect" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认</span>
      </p>
      <div style="text-align: center">
        <p>确认将材料进行汇总作业吗?</p>
        <p>将同一仓库汇总为计划性以及非计划性单据,一旦操作无法更改。</p>
      </div>
      <br />
      <div>
        <div style="text-align: center; color: red; font-size: 24px">
          需要汇总的仓库
        </div>
        <el-select
          v-model="collectCkdm"
          class="input240"
          clearable
          size="small"
          style="width: 260px"
        >
          <el-option
            v-for="dict in ckStorageOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </div>
      <div slot="footer">
        <Button type="success" size="large" long @click="handleCollect"
          >汇总</Button
        >
      </div>
    </Modal>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="720px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="12">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="dateRange"
              :picker-options="pickerOptions"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库类型" prop="rpmType">
            <el-select
              v-model="queryParams.rpmType"
              class="input240"
              placeholder="请选择入库类型"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in rpmTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rpmDjbh">
            <el-input
              v-model="queryParams.rpmDjbh"
              placeholder="请输入入库单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库仓库" prop="rpmCkdm">
            <el-select
              v-model="queryParams.rpmCkdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="综合查询" prop="integrated">
            <el-input
              type="textarea"
              v-model="queryParams.integrated"
              placeholder="输入物料代码或品名规格"
              clearable
              style="width: 520px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="14" style="text-align: center">
          <el-form-item prop="rwmZtbz">
            <el-radio-group v-model="queryParams.rpmZtbz">
              <el-radio
                v-for="dict in ZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >
                {{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item
            label="入库数小于申请数"
            prop="autoFlag"
            label-width="130px"
          >
            <el-switch
              v-model="rwdSqFlag"
              inactive-value="0"
              active-value="1"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <!-- 撤回开单对话框 -->
    <Modal v-model="check_back" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认撤回至开单？</span>
      </p>
      <div style="text-align: center">
        <p>撤回理由</p>
        <Input v-model="backRpmDesc" style="width: 75%" />
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleBack">撤回</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  listRpmMstr,
  listRpd,
  allPutRpd,
  listRpl,
  delRpl,
  getRpdDetTotal,
  rpdPost,
  backCheck,
  postRpm,
  collectRpd,
  backOrder,
  backLastOrder,
} from "@/api/putStorage/RpmMstr";
import { getAllCustomerTwo } from "@/api/project/customer";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import { listBcm } from "@/api/base/bcm";
import { printOrder } from "@/utils/ruoyi";
import { rwmPost } from "@/api/putStorage/putStorageAdd";

export default {
  name: "HalfFinish",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeTab: "second",
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      tableH: (document.body.clientHeight - 130) / 2,
      tableHData: (document.body.clientHeight - 270) / 2,

      tableHChild: (document.body.clientHeight - 280) / 2,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      // 成品/半成品入库表格数据
      RpmMstrList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      gzOpen: false,
      check_collect: false,
      //汇总仓库
      collectCkdm: null,

      addDate: true,

      RpdDetTotal: [],
      RpdDetList: [],
      RplList: [],
      check_back: false,
      // 入库类型字典
      rpmTypeOptions: [],
      storageOptions: [],
      // 所有客户代码字典
      allCustomerOptions: [],
      //单位字典
      unitFlagOptions: [],
      //有效仓库字典
      ckStorageOptions: [],

      //所有储位字典
      cwStorageOptions: [],

      //所有仓库字典
      allCkStorageOptions: [],
      //请求状态
      ZtbzOptions: [
        {
          dictLabel: "未过账",
          dictValue: "2",
        },
        {
          dictLabel: "已过帐",
          dictValue: "6",
        },
        {
          dictLabel: "全部",

          dictValue: "",
        },
      ],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 开单日期时间范围
      dateRange: [
        new Date(new Date().getTime() - 3600 * 1000 * 24 * 30),
        new Date(new Date().getTime() + 3600 * 1000 * 24 * 60),
      ],
      serachAddList: [],

      selectioned: [],
      rowData: [],
      rwdSqFlag: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        rpmDjbh: null,
        rpmType: null,
        integrated: "",
        rpmZtbz: "2",
        rpmTjflag: "1",
      },
      //撤回原因
      backRpmDesc: null,
      // 查询子项参数
      queryChildParams: {
        pageNum: 1,
        pageSize: 20,
        //入库类型
        rpdType: null,
        //入库仓库
        rpdCkdm: null,
        //客户代码
        rpdKhdm: null,
        //订单编号
        rpdDjbh: null,
        //制造单号
        rpdZZdh: null,
        //机台编号
        rpdJtbh: null,
        //物料代码
        rpdWldm: null,
        //规格描述
        rpdWlgg: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rplRksl: [
          { required: true, message: "入库数量不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    //获取入库类型字典
    this.getAllDicts("input_StorageType").then((response) => {
      this.rpmTypeOptions = response.data;
    });
    //单位
    this.getAllDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    //获取所有客户
    getAllCustomerTwo().then((response) => {
      for (let i of response.data) {
        i.dictLabel = "[" + i.cusCode + "] " + i.cusName;
        i.dictValue = i.cusCode;
        i.listClass = "default";
      }
      this.allCustomerOptions = response.data.concat([
        { dictValue: ".H", dictLabel: "海尔" },
        { dictValue: ".M", dictLabel: "美的" },
        { dictLabel: "所有客户", dictValue: "SY", listClass: "default" },
      ]);
    });

    //获取所有存储仓库
    getAll().then((response) => {
      this.allCkStorageOptions = response.data;
      for (let item of this.allCkStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    //根据状态获取存储仓库
    getstorageType("0").then((response) => {
      this.storageOptions = response.data;

      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    //根据状态获取存储仓库
    getstorageType("0").then((response) => {
      this.ckStorageOptions = response.data;

      for (let item of this.ckStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getAll().then((response) => {
      this.cwStorageOptions = response.data;
      for (let item of this.cwStorageOptions) {
        item.dictLabel = item.storageDefaultstorage;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    this.getList();
  },
  methods: {
    /** 查询成品/半成品入库列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.dateRange && "" != this.dateRange) {
        this.queryParams.params["beginRpmJlrq"] = this.moment(
          this.dateRange[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRpmJlrq"] = this.moment(
          this.dateRange[1]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["rwdSqFlag"] = this.rwdSqFlag;
      }
      this.queryParams.pageNum = 1;
      listRpmMstr(this.queryParams).then((response) => {
        this.RpmMstrList = [];
        this.rwdDetList = [];
        this.rwdDetTotal = [];
        this.RpmMstrList = this.RpmMstrList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRows(row);
        } else if (this.RpmMstrList != null && this.RpmMstrList.length > 0) {
          this.clickRows(this.RpmMstrList[0]);
        }
      });
    },
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      if (row.rpdRksl !== null && row.rpdRksl !== "") {
        return "color:#bb0331";
      }
    },
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rpmZtbz == "1" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#0fac09";
      }
      //通过
      else if (row.rpmZtbz == "2" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#0323af";
      }
      //检验
      else if (row.rpmZtbz == "6" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#bb0331";
      }
      if (row.rpmZtbz == "2" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#bb0331";
      }
    },
    /** 单击选中数据 */
    clickRows(row) {
      //获得选中的详细数据
      this.rowData = row;
      //获得当前单据的状态
      this.single = row == null || row.rpmZtbz != "2" || row.rpmTjflag != "1";
      //获得选中的详细数据
      this.getRpdDetList(row.rpmDjbh);
    },
    /** 单击选中子项数据 */
    clickRowChilds(row) {
      this.getRplLists(row.rpdWldm, row.rpdDjbh);
    },
    getRplLists(rpdWldm, rpdDjbh) {
      listRpl(rpdWldm, rpdDjbh).then((response) => {
        this.RplList = response.data;
      });
    },
    /** 获取RpdDet 数据*/
    getRpdDetList(rpdDjbh) {
      this.RpdDetList = [];
      this.RpdDetTotal = [];
      if (rpdDjbh != null && rpdDjbh != "") {
        listRpd(rpdDjbh).then((response) => {
          this.RpdDetList = response.data.detail;
          this.RpdDetTotal = response.data.total;

          if (this.RpdDetTotal.length > 0) {
            this.getRplLists(
              this.RpdDetTotal[0].rpdWldm,
              this.RpdDetTotal[0].rpdDjbh
            );
          }
        });
      }
    },
    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageNum++;
        listRpmMstr(this.queryParams).then((response) => {
          this.RpmMstrList = this.RpmMstrList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.gzOpen = false;
      this.openSearch = false;
      this.backRwmDesc = null;
      this.check_back = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rplDjbh: null,
        rplWldm: null,
        rplPmgg: null,
        rplOksl: null,
        rplYrsl: null,
        rplDrsl: null,
        rplRksl: null,
        rplCwdm: null,
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.RpmMstrList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 确认入库 */
    handRpdPut(row) {
      this.reset();
      getRpdDetTotal({ rpdDjbh: row.rpdDjbh, rpdWldm: row.rpdWldm })
        .then((res) => {
          this.form = res.data;

          this.gzOpen = true;
          this.title = "仓库过账确认";
        })
        .catch(() => {
          this.msgError("未找到数据");
        });
    },
    handleSearch() {
      this.reset();
      this.title = "查询成品/半成品入库";
      this.openSearch = true;
    },
    /** 一键入库 */
    handleAllPut() {
      this.$confirm(
        "确认将【入库单号:" + this.rowData.rpmDjbh + "】的材料进行一键入库吗?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        allPutRpd(this.rowData.rpmDjbh)
          .then((res) => {
            this.msgSuccess("一键入库成功");
            this.getRpdDetList(this.rowData.rpmDjbh);
          })
          .catch(() => {
            this.msgError("一键入库失败");
          });
      });
    },
    /** rpl 删除 */
    handRplDel(Id) {
      delRpl(Id)
        .then((res) => {
          this.msgSuccess("删除成功");
          this.getRpdDetList(this.rowData.rpmDjbh);
        })
        .catch(() => {
          this.msgError("删除失败");
        });
    },
    isEmpty() {
      for (let i of this.RpdDetTotal) {
        if (i.rpdRksl === null || i.rpdRksl === "") return true;
      }
      return false;
    },
    /** 过账 */
    handlePast() {
      if (this.isEmpty()) {
        this.$Modal.warning({
          title: "提示",
          content: "存在未确认入库数量的材料，不允许此操作",
        });
        return;
      } else {
        this.$confirm(
          "确认将【入库单号:" +
            this.rowData.rpmDjbh +
            "】的材料进行仓库过账作业吗?一旦操作系统库存将会增加，请谨慎操作。",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).then(() => {
          postRpm(this.rowData.rpmDjbh)
            .then((res) => {
              this.msgSuccess("过账成功");
              this.queryParams.pageNum = 1;
              this.RpmMstrList = [];
              this.getList();
            })
            .catch(() => {
              this.msgError("过账失败");
            });
        });
      }
    },
    /** 确认入库 */
    handleRpdPost() {
      const data = this.form;
      rpdPost(this.form)
        .then((res) => {
          this.getRpdDetList(this.rowData.rpmDjbh);
          this.cancel();
          this.msgSuccess("确认入库成功");
        })
        .catch(() => {
          this.msgError("确认入库失败");
        });
    },
    /** 汇总 */
    handleCollect() {
      if (this.collectCkdm != null && this.collectCkdm != "") {
        let data = {
          rpmCkdm: this.collectCkdm,
          rpmJlrq: this.queryParams.params["beginRpmJlrq"],
          rpmJlrqEnd: this.queryParams.params["endRpmJlrq"],
        };
        console.log(data);
        collectRpd(data)
          .then((res) => {
            this.msgSuccess("汇总成功");
            this.queryParams.pageNum = 1;
            this.getList();
            this.check_collect = false;
          })
          .catch(() => {
            this.msgError("汇总失败");
          });
      } else {
        this.msgError("请选择仓库");
      }
    },
    /** 撤回检验*/
    // handleBack() {
    //   backCheck(this.rowData.rpmId, this.rowData.rpmDjbh)
    //     .then((res) => {
    //       this.getList()
    //       this.msgSuccess('撤回检验成功')
    //     })
    //     .catch(() => {
    //       this.msgError('撤回检验失败')
    //     })
    // },

    //撤回开单
    handleBack() {
      if (this.backRpmDesc == null || this.backRpmDesc == "") {
        this.msgError("请输入撤回理由~");
        return;
      }
      const data = {
        rpmId: this.rowData.rpmId,
        rpmDjbh: this.rowData.rpmDjbh,
        rpmJyjg: "",
        rpmDesc: this.backRpmDesc,
        rpmZtbz: 1,
        rpmTjflag: 0,
      };
      backLastOrder(data)
        .then((res) => {
          this.msgSuccess("撤回成功");
          this.queryParams.pageNum = 1;
          this.cancel();
          this.getList();
        })
        .catch(() => {
          this.msgError("撤回失败");
        });
    },
    //单据打印
    printHandle(row) {
      const data = { rpmDjbh: row.rpmDjbh };
      if (row.rpmZtbz != "6") {
        this.$confirm("当前单据还未过账，是否过账并执行打印？", "温馨提醒", {
          confirmButtonText: "过账并打印",
          cancelButtonText: "取消",
          type: "info",
        }).then((res) => {
          postRpm(row.rpmDjbh)
            .then((res) => {
              this.msgSuccess("过账成功");
              this.queryParams.pageNum = 1;
              this.RpmMstrList = [];
              this.getList();
              printOrder(
                "/putStorage/RpmMstr/exportIncomingGoodsTemplate",
                data,
                "成品_半成品入库单"
              );
            })
            .catch(() => {
              this.msgError("过账失败");
            });
        });
        return;
      }
      printOrder(
        "/putStorage/RpmMstr/exportIncomingGoodsTemplate",
        data,
        "成品_半成品入库单"
      );
      /*      for (let i = 0; i < this.allCustomerOptions.length; i++) {
              if (this.allCustomerOptions[i].dictValue == a.chmKhdm) {
                this.printRy = this.allCustomerOptions[i].dictLabel
                break
              }
            }
            this.printRq = a.chmGzrq
            this.printDh = a.chmDjbh
            this.printDiag = true*/
    },
    /** 导出按钮操作 */
    handleExport() {},
  },
};
</script>

<style lang="scss" scoped></style>
